<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
  >
    <template #searchPanel>
      <search-panel
       v-slot="{ form }"
        :addPer="'brandCheckStorage:save'"
        :selectPer="'brandCheckStorage:page'"
        addTitle="新增盘点单"
        @insert="add"
        @search="search"
        :showSearchButton="true"
        :showAddButton="true"
      >
        <Job-shop v-model="form.storeId" placeholder="所属门店" />
        <el-select
          clearable
          style="width: 200px"
          v-model="form.status"
          placeholder="状态"
        >
          <el-option
            v-for="item in dict['盘点状态']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input
          v-model="form.code"
          clearable
          placeholder="盘点单号"
          style="width: 200px"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
         @row-dblclick="view"
      >
        <template #action="{ row }">
          <i
            class="el-icon-edit"
            title="编辑"
            style="margin-left: 15px; cursor: pointer"
            v-permission="'brandCheckStorage:findById'"
            @click="handleDataUpdateEdit(row, '编辑')"
          ></i>
          <i
            class="el-icon-delete"
            title="删除"
            style="color: red; margin-left: 20px; cursor: pointer"
            v-permission="'brandCheckStorage:del'"
            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>
    </template>
    <template #dialog>
      <dialog-view-detail
        @operate="handleDataOperate"
        :id="viewId"
        @oncancel="dialogClose"
      />
    </template>
  </base-layout>
</template>
<script>
import baseMixin from '@/mixins/base'
import { getDict } from '@/utils'
import {
  page,
  deleteById,
} from '@/api/pre-sale/boutiqueStock/inventoryCheck'
import { findByStore } from '@/api/after-sale/storehouseManage/warehouseManage'
import DialogViewDetail from './view/index.vue'
export default {
  components: {
    DialogViewDetail,
  },
  mixins: [
    baseMixin({
      idName: 'id',
      findData: page,
      dataName: ['content', 'totalRecords'],
      format(res) {
        return res.map((data) => {
          data.preferred = data.preferred == true ? '是' : '否'
          data.openRestsStoreName =
            data.openRestsStore == true ? '启用' : '禁用'

          return data
        })
      },
      deleteData: deleteById,
    }),
  ],
  data() {
    return {
      tableColumnAttributes: [
        { name: '盘点门店', value: 'storeName', type: 'text' },
        { name: '盘点单号', value: 'code', type: 'text' },
        { name: '单据日期', value: 'receiptsTime', type: 'text' },
        { name: '盘点任务名', value: 'name', type: 'text' },
        { name: '盘点仓库', value: 'storageName', type: 'text' },
        { name: '仓库编号', value: 'storageCode', type: 'text' },
        { name: '盘点精品', value: 'checkNumber', type: 'text' },
        // { name: '配件总金额', value: 'amount', type: 'text' },
        { name: '盘点负责人', value: 'userName', type: 'text' },
        { name: '负责人联系方式', value: 'userPhone', type: 'text' },
        { name: '状态', value: 'status', type: 'text' },
        { name: '盘盈数量', value: 'profitNum', type: 'text' },
        { name: '盘亏数量', value: 'lossNum', type: 'text' },
        { name: '正常数量', value: 'normalNum', type: 'text' },
        { name: '备注', value: 'remark', type: 'text' },
      ],
      dict: [],
      dialogVisible: false,
      storageList: [],
      form: {
        storeId: '',
      },
    }
  },
  watch: {},
  methods: {
    add() {
      this.$router.push({ name: 'addStorageChecking' })
    },
    handleDataUpdateEdit(row, type) {
      if (row.status != '盘点完成') {
        this.$router.push({
          name: 'addStorageChecking',
          query: {
            id: row.id
          }
        })
      } else {
        this.$message.error('盘点已完成，无法修改数据')
      }
    },
    // 查看入库
    view(row) {
      this.viewId = row.id;
      this.handleDataInsert("盘点详情");
    },
    search(form) {
      console.log(form)
      this.searchOptions = form
      this.currentPage = 1
      this.setTableData()
    },
  },
  mounted() {
    this.dict = getDict(['盘点状态'])
  },
}
</script>
